<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
	<div class="page-header">
		<h1>
            <a class="a-back" href="<?= admin_url('admin/brand/' . $schoolInfo['id']) ?>">
                <i class="fa fa-reply"></i>
            </a>
            批量添加班牌：<?= $schoolInfo['school_name'] ?>
        </h1>
	</div>
	<div class="col-xs-12">
		<form class="form-horizontal" id="classes-form">
			<input type="hidden" name="id" value="<?= isset($videoInfo['id']) ? $videoInfo['id'] : 0 ?>" />
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">选中班级：</label>
				<div class="col-sm-6">
					<?php foreach($gradeArray as $key => $grade): ?>
						<div class="well well-sm">
							<a class="blue select-grade" href="javascript:;" title="全选年级"><?=$key?> <span style="color: #999;margin-left: 5px">(点击选中全部班级)</span></a>
							<div class="mt5">
							<?php foreach($grade['class'] as $class): ?>
								<label class="inline checkbox-item mr20">
									<input class="ace" type="checkbox" name="brand_class" value="<?=$class['id']?>" />
									<span class="lbl"> <?=$class['class_name']?></span>
								</label>
							<?php endforeach; ?>
							</div>
						</div>
					<?php endforeach; ?>
				</div>
			</div>
			<div class="clearfix">
				<div class="col-md-offset-3 col-md-9">
					<a class="btn btn-info submit">
						<i class="ace-icon fa fa-check"></i> 提交
                    </a>
				</div>
			</div>
		</form>
	</div>
<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	$(function(){

		// 点击年级，全选下级班级
		var cancel = false;
		$(".select-grade").click(function(){
			// 第一选择，第二次取消选择
			if(cancel) {
				// 取消选择
				$(this).parent().find("[name=brand_class]").each(function(){
					$(this)[0].checked = false;
				});
				cancel = ! cancel;
			} else {
				// 选择
				$(this).parent().find("[name=brand_class]").each(function(){
					$(this)[0].checked = true;
				});
				cancel = ! cancel;
			}
		})

		$(".submit").click(function() {
			var id = $("[name=id]").val();
			var brandClassArr = [];
			$("[name=brand_class]").each(function() {
				if($(this).prop("checked")) {
					brandClassArr.push($(this).val());
				}
			});
			var brandClass = brandClassArr.join(',');
            var count = brandClassArr.length;
            if(count == 0) {
                tips_alert("请先选中班级", false);
				return;
            }
            layer.confirm('确定添加班牌，个数：' + count + '？', { title:"提示", offset: '160px' }, function(){
                var url = "<?=admin_url('admin/save_brand_batch_action/' . $schoolInfo['id'])?>";
                var data = {
                    "brand_class": brandClass,
                };
                ajax_post(url, data, function() {
                    window.location.href = "<?=admin_url('admin/brand/' . $schoolInfo['id'])?>";
                });
			});
		});
	})
</script>